import { runCommand } from ".";

export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        runCommand(context, options, isUndo, (sheet, options) => {
            const { selections, underline } = options;
            selections.forEach(range => {
                if (underline === 'underline') {
                    sheet.getRange(range.row == -1 ? 0 : range.row, range.col == -1 ? 0 : range.col , range.rowCount, range.colCount).textDecoration(window.GC.Spread.Sheets.TextDecorationType.underline);
                } else {
                    sheet.getRange(range.row == -1 ? 0 : range.row, range.col == -1 ? 0 : range.col , range.rowCount, range.colCount).textDecoration(window.GC.Spread.Sheets.TextDecorationType.none);
                }
            })
        })
    }
};
/* export default {
    canUndo: true,
    execute: (context, options, isUndo) => {
        const { sheet, selections, _oldValue, underline } = options;
        sheet.suspendPaint();
        if (isUndo) {
            selections.forEach(range => {
                for (let row = range.row, i = 0; i < range.rowCount; i++ , row++) {
                    for (let col = range.col, j = 0; j < range.colCount; j++ , col++) {
                        const cell = sheet.getCell(row, col);
                        cell.textDecoration(_oldValue[row][col]);
                    }
                }
            });
        } else {
            selections.forEach(range => {
                for (let row = range.row, i = 0; i < range.rowCount; i++ , row++) {
                    for (let col = range.col, j = 0; j < range.colCount; j++ , col++) {
                        const cell = sheet.getCell(row, col);
                        const oldValue = cell.textDecoration();
                        if (!options._oldValue) {
                            options._oldValue = {};
                        }
                        if (!options._oldValue[row]) {
                            options._oldValue[row] = {};
                        }
                        options._oldValue[row][col] = oldValue;
                        if (underline === 'underline') {
                            cell.textDecoration(GC.Spread.Sheets.TextDecorationType.underline);
                        } else {
                            cell.textDecoration(GC.Spread.Sheets.TextDecorationType.none);
                        }
                    }
                }
            });
        }
        sheet.resumePaint();
    }
}; */